<template>
    <div class="content">
        <el-form style="margin-top: 20px;" ref="form" :model="formModel" :rules="rules" label-width="200px">
            <el-form-item label="是否显示软件服务许可协议：" prop="name">
                <el-radio v-model="formModel.isShow2" :label='true'>是</el-radio>
                <el-radio v-model="formModel.isShow2" :label='false'>否</el-radio>
            </el-form-item>
            <el-form-item label="协议标题：" prop="text1">
                <el-input style="width: 200px" v-model="formModel.text1" maxlength='20' placeholder="请输入" clearable></el-input>
            </el-form-item>
          </el-form>
        <el-form style="margin-top: 20px;" :model="formModel" label-width="100px" label-position='top'>
            <el-form-item label="协议内容：" prop="name">
                <Editor v-model="formModel.longtext" :height="500" />
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
    import {tools} from '@/utils/tools.js'
    import Editor from '@/components/Editor';
    export default {
        components: {
            Editor
        },
        props:{
            formModel:{
                type: Object,
                default: res=>{}
            }
        },
        data() {
            return {
                checkedPayWay: [],
                checkedSendWay: [],
                payWaysDict: {},
                sendWaysDict: {},
                longtext: '',
                rules: {
                    text1: [{ required: true, message: '请输入', trigger: 'blur' }]
                },
            }
        },
        created(){
            if(!this.formModel.text1){
                this.formModel.text1 = '购买协议'
            }
            this.payWaysDict = tools.paramsToObj(this.formModel.options1)
            this.sendWaysDict = tools.paramsToObj(this.formModel.options2)
        },
        methods:{
            //子组件校验，传递到父组件
            validateForm () {
                let flag = false
                this.$refs['form'].validate(valid => {
                    if (valid) {
                        var payWays = ''
                        if(this.checkedPayWay.length>0){
                            for(var item of this.checkedPayWay){
                                payWays = payWays+item+'=1&'
                            }
                            payWays = payWays.substring(0, payWays.length-1)
                        }
                        this.formModel.options1 = payWays
                        var sendWays = ''
                        if(this.checkedSendWay.length>0){
                            for(var item of this.checkedSendWay){
                                sendWays = sendWays+item+'=1&'
                            }
                            sendWays = sendWays.substring(0, sendWays.length-1)
                        }
                        this.formModel.options2 = sendWays
                        flag = true
                    } else {
                        flag = false
                    }
                })
                return flag
            },
        }
    }
</script>